<template>
  <div>
    <el-row>
      <el-col :span="8" :offset="8">
        <el-form ref="settingForm" label-width="160px" :model="form">
          <el-form-item label="单选题数（专题）">
            <el-input-number v-model="form.scNum" :min="0" :max="500" :step="1" label="描述文字"></el-input-number>
          </el-form-item>
          <el-form-item label="判断题数（专题）">
            <el-input-number v-model="form.tfNum" :min="0" :max="500" :step="1" label="描述文字"></el-input-number>
          </el-form-item>
          <el-form-item label="专题考试时间（分钟）">
            <el-input-number v-model="form.examTime" :min="1" :max="500" :step="1" label="描述文字"></el-input-number>
          </el-form-item>
          <el-form-item label="单选题分数">
            <el-input-number v-model="form.scScore" :min="0" :max="500" :step="1" label="描述文字"></el-input-number>
          </el-form-item>
          <el-form-item label="判断题分数">
            <el-input-number v-model="form.tfScore" :min="0" :max="500" :step="1" label="描述文字"></el-input-number>
          </el-form-item>
          <el-form-item label="试卷合格分数">
            <el-input-number v-model="form.qualifiedScore" :min="0" :max="10000" :step="1"
                             label="描述文字"></el-input-number>
          </el-form-item>
        </el-form>
        <div>
          <el-button type="primary" style="width: 100%" @click="submit" :disabled="submitting" :loading="submitting">保存</el-button>
        </div>
      </el-col>
    </el-row>

  </div>
</template>

<script>
import {get, set} from '@/api/examSetting.js'

export default {
  name: 'exam-setting',
  data () {
    return {
      form: {
        scNum: 10,
        tfNum: 10,
        scScore: 5,
        tfScore: 5,
        qualifiedScore: 80
      },
      submitting: false
    }
  },
  created () {
    this.getSetting()
  },
  methods: {
    getSetting () {
      get().then((res) => {
        this.form = res.data.data
      })
    },
    submit () {
      this.$refs.settingForm.validate((valid) => {
        if (valid) {
          this.submitting = true
          set(this.form).then(() => {
            this.$message.success('保存成功')
          }).finally(() => { this.submitting = false })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
